<template>
  <div>
    <!-- 页面,面包屑 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片充当白色背景 -->
    <el-card class="box-card">
      <!-- 栅格 24 -->
      <el-row>
        <el-col :span="6">
          <el-input placeholder="请输入内容" clearable v-model="queryInfo.query">
            <el-button slot="append" class="el-icon-search"
                       @click="getOrderList">
            </el-button>
          </el-input>
        </el-col>
      </el-row>
      <el-table :data="tableData" border style="width: 100%">
        <el-table-column type="index" label="序号" width="50"> </el-table-column>
        <el-table-column prop="order_number" label="订单编号"></el-table-column>
        <el-table-column prop="order_price" label="订单价格"></el-table-column>
        <el-table-column prop="order_pay" label="是否付款">
          <!-- 作用域插槽 -->
          <template slot-scope="scope">
            <el-tag v-if="scope.row.order_pay==='0'" type="danger">未付款</el-tag>
            <el-tag v-else type="success">已付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货"></el-table-column>
        <el-table-column prop="create_time" label="下单时间">
          <!-- 作用域插槽 -->
          <template slot-scope="scope">
            {{scope.row.create_time | dataFormat}}
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <el-button type="primary" size="mini" icon="el-icon-edit"
                     @click="showAddr" />
          <el-button type="success" size="mini" icon="el-icon-location"
                     @click="showLoacl" />
        </el-table-column>
      </el-table>
      <!-- 分页的信息 -->
      <el-pagination @size-change="handleSizeChange"
                     @current-change="handleCurrentChange"
                     :current-page="queryInfo.pagenum" :page-sizes="[10,15,20]"
                     :page-size="queryInfo.pagesize"
                     layout="total, sizes, prev, pager, next, jumper"
                     :total="total">
      </el-pagination>
      <!-- 添加地址 -->
      <el-dialog title="添加地址" class="mydialog" @close='addFormClose'
                 :visible.sync="dialogFormVisibleAdd">
        <el-form ref="ruleFormRef" :model="addForm" :rules="rules"
                 label-width="80px" class="demo-ruleForm">
          <el-form-item label="省市区/县" prop="addr">
            <el-cascader v-model="addForm.addr" :options="options"
                         :props='props'>
            </el-cascader>
          </el-form-item>
          <el-form-item label="详细地址" prop="detailAddr">
            <el-input v-model="addForm.detailAddr"></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogFormVisibleAdd = false">取 消</el-button>
          <el-button type="primary" @click="submiAddForm">确 定
          </el-button>
        </div>
      </el-dialog>
      <!-- 展示物流 -->
      <el-dialog title="展示物流" class="mydialog"
                 :visible.sync="dialogLocalVisible">
        <el-timeline :reverse="true">
          <el-timeline-item v-for="(activity, index) in timelineDate"
                            :key="index" :timestamp="activity.ftime"
                            :icon="activity.icon" :type="activity.type"
                            :color="activity.color" :size="activity.size">
            {{activity.context}}
          </el-timeline-item>
        </el-timeline>
      </el-dialog>
    </el-card>
  </div>
</template>

<script>
// 先把数据导进来
import cityData from './citydata'
import localData from './localdata'
export default {
  mounted () {
    this.getOrderList()
  },
  data () {
    return {
      timelineDate: [],
      // 展示物流
      dialogLocalVisible: false,
      // 展示地址
      dialogFormVisibleAdd: false,
      // 添加地址的form对象
      addForm: {
        addr: [],
        detailAddr: ''
      },
      // 3级联动的数据
      options: [],
      // 税局和列表的对应关系,本省就是label,value和children
      props: { expandTrigger: 'hover' },
      tableData: [],
      queryInfo: {
        query: '',
        pagenum: 1,
        pagesize: 10
      },
      total: 0,
      rules: {
        addr: [
          { required: true, message: '必填的', trigger: 'blur' },
        ],
        detailAddr: [
          { required: true, message: '必填的', trigger: 'blur' },
        ],
      },
    }
  },
  methods: {
    // 展示物流信息的表嘎
    showLoacl () {
      this.dialogLocalVisible = true
      // const { data: { data, meta } } = await this.$axios.get(`/kuaidi/1106975712662`)
      this.timelineDate = localData;
      // console.log(data, meta)
    },
    // 当dialog 关闭的时候清空表单
    addFormClose () {
      this.$refs.ruleFormRef.resetFields();
    },
    /* 提交表单的数据 */
    submiAddForm () {
      console.log(this.addForm)
      this.dialogFormVisibleAdd = false;
    },
    // 修改地址
    showAddr () {
      this.dialogFormVisibleAdd = true;
      console.log(cityData)
      this.options = cityData;
    },
    // 获取订单列表
    async getOrderList () {
      const { data: { data, meta } } = await this.$axios.get('orders', { params: this.queryInfo })
      console.log(data, meta)
      if (meta.status !== 200) {
        return this.$message.error('获取数据失败')
      }
      this.tableData = data.goods
      this.total = data.total
      this.$message.success('获取订单列表成功')
    },
    handleSizeChange (newsize) {
      this.queryInfo.pagesize = newsize;
      this.getOrderList()
    },
    handleCurrentChange (newpage) {
      console.log(newpage)
      this.queryInfo.pagenum = newpage
      this.getOrderList()
    },
  }
}
</script>

<style lang="css" scoped>
.el-cascader {
  width: 100%;
}
.el-timeline-item {
  text-align: left;
}
/* .el-card{
  text-align: left;
}
.el-input{
  max-width: 400px;
} */
</style>